package huanzhao.erp.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import huanzhao.erp.domain.types.OperationTarget;
import huanzhao.erp.domain.types.OperationType;
import huanzhao.erp.domain.types.PhoneAttr;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@TableName(value = "operation")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Operation implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;


    @TableField(value = "time")
    private Date time;


    @TableField(value = "staff_id")
    private Long staffId;


    @TableField(value = "type")
    private OperationType type;

    /**
     * 操作对象
     */
    @TableField(value = "target")
    private OperationTarget target;


    @TableField(value = "relate_id")
    private Long relateId;

    /**
     * 操作的属性，例如手机字段名称
     */
    @TableField(value = "attribute")
    private PhoneAttr attribute;


    @TableField(value = "detail")
    private String detail;

    @Serial
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    public Operation(Long staffId, OperationType type, OperationTarget target, Object detail, Long relateId, PhoneAttr attr) {
        this.staffId = staffId;
        this.type = type;
        this.target = target;
        this.relateId = relateId;
        this.attribute = attr;
        if (detail != null) {
            this.detail = detail.toString();
        }
    }
}